<template>
  <div>
    <!-- 点击登录显示提示框 -->
    <el-dialog title="手机号登录" :visible.sync="dialogVisible" width="530px">
      <!-- 收集表单存放model  继续表单验证rules  -->
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="ruleForm.phone"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="ruleForm.password"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmLogin">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      // 提示框关闭
      dialogVisible: false,
      // ruleForm 表单信息
      ruleForm: {
        phone: "13570969674",
        password: "wrn2713664",
      },
      // 表单验证
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern:
              /^(([0-9]{11})|([0-9]{3}\-[0-9]{8})|([0-9]{4}\-[0-9]{7}))$/,
            message: "请输入正确手机号",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 5,
            max: 10,
            message: "长度在 5 到 10 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted(){
  },
  methods: {
    // 点击登录按钮
    async confirmLogin() {
      // 因为要不只一个人用token所以在vuex保存
      // this.$API.reqPhoneLogin
      try {
        await this.$store.dispatch("getPhoneLogin", this.ruleForm);
        this.dialogVisible = false;
        
      } catch (error) {
        alert("请输入正确的账号或者密码");
      }
    },
    changeDialog() {
        this.dialogVisible = true
    },

  },
  
};
</script>

<style></style>
